import api from '../../../utils/api.js';//这个里面封装了request方法

// pages/purchaseHall/purchaseFriend/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mypurchaseforms:[
      {
          "formId": "1",
          "userId": "1",
          "catId": "1",
          "itemId": "1",
          "cycle": "day",
          "count": 2000,
          "receiptAddress": "湖南",
          "expectedAddress": "河北",
          "price": 2.0,
          "description": null,
          "offercount": 1,
          "status": 1,
          "units": "斤",
          "ddl": "2021-07-15",
          "totalcount": 2000,
          "itemName": "西瓜",
          "categoryId": "1",
          "image1": "https://dcdn.it120.cc/2021/07/15/b1763660-78bd-4a2d-bbae-9e68dc76bdbc.png",
          "image2": null
      }],
    myapplyforms:[  {
      
        "saleuserId": "1",
        "formId": "2",
        "count": 300,
        "price": 0.7,
        "fromAddress": "湖南",
        "offerstatus": 2,
        "saleusername": "xp",
        "salehead": "",
        "formstatus": 0,
        "units": "个",
        "itemId": "10",
        "itemName": "鸡蛋",
        "image1": "https://dcdn.it120.cc/2021/07/15/f0a26c05-afee-4ea7-a410-d9cdee090a7d.png"
    
  }
      // formId:'',
      // itemName:'',
      // count:'11',//我供应的数量
      // price:'12',//我的报价
      // units:'斤',
      // formstatus:0,//订单状态
      // image1:''}
    ],

 

  },
 
  getMypurchaseFormsByUserId(){
    console.log("getMypurchaseFormsByUserId");
    const url = 'forms/users/'+app.globalData.userId;
    console.log(url)
    api.get(url).then(res => {
          //得到的数据
          let { code, data, msg } = res;
          console.log(res);
          this.setData({mypurchaseforms:res.data})
          wx.showToast({
            title: msg,
            icon: 'none'
          })

        }).catch(err => {
          console.log(err)
          wx.showToast({
            title: "请求错误",
            icon: 'none'
          })
        })
    
  },
  getMyApplyDetails(){
    console.log("getMyApplyDetails")
    const url = 'formOffers/users/'+app.globalData.userId;
    api.get(url).then(res => {
          //得到的数据
          let { code, data, msg } = res;
          console.log(res);
          this.setData({myapplyforms:res.data})
          // wx.showToast({
          //   title: msg,
          //   icon: 'none'
          // })

        }).catch(err => {
          console.log(err)
          // wx.showToast({
          //   title: "请求错误",
          //   icon: 'none'
          // })
        })


  },
  onChange(){
    console.log("onchange")
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    this.getMypurchaseFormsByUserId();
    this.getMyApplyDetails();
  }
})
Component({
  /**
   * 页面的初始数据
   */
  data: {
    bottomimg:'',

  mypurchaseforms:[
    {
        "formId": "1",
        "userId": "1",
        "catId": "1",
        "itemId": "1",
        "cycle": "day",
        "count": 2000,
        "receiptAddress": "湖南",
        "expectedAddress": "河北",
        "price": 2.0,
        "description": null,
        "offercount": 1,
        "status": 1,
        "units": "斤",
        "ddl": "2021-07-15",
        "totalcount": 2000,
        "itemName": "西瓜",
        "categoryId": "1",
        "image1": "https://dcdn.it120.cc/2021/07/15/b1763660-78bd-4a2d-bbae-9e68dc76bdbc.png",
        "image2": null
    }],
  myapplyforms:[  {
    
      "saleuserId": "1",
      "formId": "2",
      "count": 300,
      "price": 0.7,
      "fromAddress": "湖南",
      "offerstatus": 2,
      "saleusername": "xp",
      "salehead": "",
      "formstatus": 0,
      "units": "个",
      "itemId": "10",
      "itemName": "鸡蛋",
      "image1": "https://dcdn.it120.cc/2021/07/15/f0a26c05-afee-4ea7-a410-d9cdee090a7d.png"
  
}
    // formId:'',
    // itemName:'',
    // count:'11',//我供应的数量
    // price:'12',//我的报价
    // units:'斤',
    // formstatus:0,//订单状态
    // image1:''}
  ],



},

  /**
   * 函数
   */
  methods: {
    
getMypurchaseFormsByUserId(){
  console.log("getMypurchaseFormsByUserId");
  const url = 'forms/users/'+app.globalData.userId;
  console.log(url)
  api.get(url).then(res => {
        //得到的数据
        let { code, data, msg } = res;
        console.log(res);
        this.setData({mypurchaseforms:res.data})
        wx.showToast({
          title: msg,
          icon: 'none'
        })

      }).catch(err => {
        console.log(err)
        wx.showToast({
          title: "请求错误",
          icon: 'none'
        })
      })
  
},
getMyApplyDetails(){
  console.log("getMyApplyDetails")
  const url = 'formOffers/users/'+app.globalData.userId;
  api.get(url).then(res => {
        //得到的数据
        let { code, data, msg } = res;
        console.log(res);
        this.setData({myapplyforms:res.data})
        // wx.showToast({
        //   title: msg,
        //   icon: 'none'
        // })

      }).catch(err => {
        console.log(err)
        // wx.showToast({
        //   title: "请求错误",
        //   icon: 'none'
        // })
      })


},
onChange(){
  console.log("onchange")
  this.getMypurchaseFormsByUserId();
  this.getMyApplyDetails();
},
  },
  /**
   * 页面加载完成执行
   */
  lifetimes:{
    ready(){
      console.log("lifttime")
      this.getMypurchaseFormsByUserId();
      this.getMyApplyDetails();
    }
  },
  attached(){
     // 第二种方式通过组件的生命周期函数执行代码
   },
 })
 